Skip to content

fix(openapi-fetch): don't rely on DOM types #1827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

ngraef
Copy link
Contributor

@ngraef ngraef commented Aug 7, 2024

Changes

This PR changes typing to avoid the global HeadersInit, which is declared in the DOM lib and therefore typically not included in Node projects.

Resolves #1823
Resolves #1824
Resolves #1735

How to Review

How can a reviewer review your changes? What should be kept in mind for this review?

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

@ngraef ngraef requested a review from a team as a code owner August 7, 2024 18:08
Copy link

changeset-bot bot commented Aug 7, 2024

🦋 Changeset detected

Latest commit: 19887b0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
openapi-fetch Patch
openapi-react-query Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -24,7 +24,7 @@ export interface ClientOptions extends Omit<RequestInit, "headers"> {
}

export type HeadersOptions =
| HeadersInit
| Required<RequestInit>["headers"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change pulls a reference to HeadersInit from RequestInit rather than relying on the global declaration, which only exists in the DOM lib. In projects with the DOM lib, this reference will resolve to HeadersInit declared in lib.dom.d.ts. In projects with Node types and no DOM lib, this reference will resolve to HeadersInit from undici-types/fetch.d.ts as referenced from @types/node/globals.d.ts.

Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing! I agree with this logic. And here, existing tests will work. Thank you for improving!

@drwpow drwpow merged commit ba0d595 into openapi-ts:main Aug 7, 2024
7 checks passed
@github-actions github-actions bot mentioned this pull request Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants